<?php
namespace froyo\cherry\Base;

use froyo\cherry\Exception\NotFoundException;

class BaseResponse extends BaseObject{
	public $httpCode = 200;
	public $data;
	public $headers = [];
	public $formatter = 'html';
	public $dataformatter = null;


    /**
     * @return mixed
     */
    public function getFormatter()
    {
        return $this->formatter;
    }

    /**
     * @param mixed $formatter
     *
     * @return self
     */
    public function setFormatter($formatter)
    {
        $this->formatter = $formatter;
        $this->dataformatter = null;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getHttpCode()
    {
        return $this->httpCode;
    }

    /**
     * @param mixed $httpCode
     *
     * @return self
     */
    public function setHttpCode($httpCode)
    {
        $this->httpCode = $httpCode;

        return $this;
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @param mixed $data
     *
     * @return self
     */
    public function setData($data)
    {
        $this->data = $data;

        return $this;
    }

    /**
     * @return mixed
     */
    public function getHeaders()
    {
        return $this->headers;
    }

    /**
     * @param mixed $headers
     *
     * @return self
     */
    public function setHeaders($headers)
    {
        $this->headers = $headers;

        return $this;
    }

    public function setHeader($name,$value){
    	$this->headers[$name] = $value;
    }

    public function clearFlush(){
    	ob_get_length() ? ob_clean() : '';
    }

    public function senderHeader(){
    	foreach ($this->headers as $name => $value) {
    		header($name.':'.$value);
    	}
    }



    public function send(){
    	$this->clearFlush();
    	http_response_code($this->httpCode);
    	$this->senderHeader();
    	echo $this->data;
    }
}